﻿@using LY.Business.ServiceImpl
@using LY.Entity
@using LY.Entity.Entities
@using LY.Interface

@{
    Layout = null;
    T_Investment investment = ViewBag.investmen;
    T_Project_EX Tproject = ViewBag.Tproject;
    U_Member member = ViewBag.member;
    T_RepaymentPlan repayment = ViewBag.repayment;
    List<T_RepaymentPlan_EX> listRepayment = ViewBag.listRepayment;
}

<link href="~/Content/fore/foreMasterPage.css" rel="stylesheet" />
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="~/scripts/lhgdialog/lhgdialog.js?skin=idialog"></script>
<script type="text/javascript">
    $(function () {
        $("#btnDownload").click(function () {
            $.dialog.tips('数据加载中...', 600, 'loading.gif');
            $("#down_file").attr("src", "/Claims/Download?number=@ViewBag.SubmitBidNo");
            $.dialog.tips('数据加载完毕', 2, loading.gif, function () { });

        });
    });
</script>

<style>
    .main, .main > div {
        padding: 20px;
    }

        .main > div {
            text-align: center;
        }

    table tr {
        border: 1px solid #ebd8d8;
    }

    table td {
        border-right: 1px solid #ebd8d8;
        width: 5%;
        height: 35px;
        text-align: center;
        font-size: 15px;
    }

    .button {
        margin-top: 5px;
    }

    .main table ~ table tr:first-child {
        background-color: #ff6666;
        color: white;
    }
</style>

<div class="main">
    <div>项目详情</div>
    <table>
        <tr>
            <td>投资人</td>
            <td>@member.Name</td>
            <td>身份证号码</td>
            <td>@LY.Common.Utils.Tools.MyChar('*', 10, member.IDCode, 6, 4) </td>
        </tr>
        <tr>
            <td>联系电话</td>
            <td>@LY.Common.Utils.Tools.MyChar('*', 4, member.Mobilenumber, 3, 4)</td>
            <td>项目名称</td>
            <td>@Tproject.ProjectName</td>
        </tr>
        <tr>
            <td>项目编号</td>
            <td>@Tproject.ProjectNo</td>
            <td>投资时间</td>
            <td>@Convert.ToDateTime(investment.CreateTime).ToString("yyyy-MM-dd")</td>
        </tr>
        <tr>
            <td>投资金额</td>
            <td>@investment.TenderAmt</td>
            <td>起息时间</td>
            <td>
                @if (Tproject.LoanTime != null)
                {
                    @Convert.ToDateTime(Tproject.LoanTime).ToString("yyyy-MM-dd HH:mm:ss")
                }
            </td>
        </tr>
        <tr>
            <td>投资期限</td>
            <td>
                @Tproject.ProjectDurationStr
            </td>
            <td>计息结束时间</td>
            <td>
                @if (Tproject.LoanTime != null)
                {
                    @Convert.ToDateTime(Tproject.ProjectEndStr).ToString("yyyy-MM-dd HH:mm:ss")
                }
            </td>
        </tr>
        <tr>
            <td>预期年化率</td>
            <td>@Math.Round((decimal)Tproject.AnnualisedRates * 100 + (decimal)Tproject.AddAnnualisedRates * 100, 2)%</td>
            <td>获得积分</td>
            <td>@(Convert.ToInt32(investment.TenderAmt * (decimal)0.2))</td>
        </tr>
    </table>

    <div>回款计划</div>
    <table>
        <tr>
            <td>回款日期</td>
            <td>回收本金(元)</td>
            <td>预期收益(元)</td>
            <td>服务费(元)</td>
            <td>累计回收(元)</td>
            <td>状态</td>
        </tr>
        @{
            decimal BenJin = 0;
            decimal YuQi = 0;
            decimal FuWu = 0;
            decimal HuiShou = 0;
            var i = 0;
            decimal sumYuQi = 0;
            decimal sumFuWu = 0;
            decimal sumHuiShou = 0;
            var EndTime = "";//回款日期
            var Dur = Convert.ToInt32(Tproject.ProjectDuration);//借款期限 （几个月）
            foreach (var plan in listRepayment)
            {
                i++;
                BenJin = i == listRepayment.Count ? investment.TenderAmt : 0;
                DateTime dat1 = DateTime.Parse(DateTime.Now.Year + "-01-01");
                DateTime dat2 = dat1.AddYears(1);
                TimeSpan spanTime = (dat2 - dat1);
                var MonthOrDay = Tproject.DurationMonthOrDay == 1 ? 12 : spanTime.Days / (decimal)Tproject.ProjectDuration;
                YuQi = investment.TenderAmt * ((decimal)Tproject.AnnualisedRates + (decimal)Tproject.AddAnnualisedRates) / MonthOrDay;
                FuWu = YuQi * Convert.ToDecimal(ViewBag.ZQFee);
                HuiShou = i == listRepayment.Count ? YuQi * (decimal)(1 - Convert.ToDecimal(ViewBag.ZQFee)) + investment.TenderAmt : YuQi * (decimal)(1 - Convert.ToDecimal(ViewBag.ZQFee));

                sumYuQi += Math.Round(YuQi, 2);
                sumFuWu += Math.Round(YuQi * Convert.ToDecimal(ViewBag.ZQFee), 2);
                sumHuiShou += Math.Round(YuQi * (decimal)(1 - Convert.ToDecimal(ViewBag.ZQFee)), 2);

                if (Tproject.LoanTime != null)
                {
                    if (Tproject.DurationMonthOrDay == 1)//月
                    {
                        Dur = Dur + 1;
                        EndTime = Convert.ToDateTime(Tproject.LoanTime).AddMonths(Dur).ToString("yyyy-MM-dd");
                    }
                    else//天
                    {
                        EndTime = Convert.ToDateTime(Tproject.LoanTime).AddDays(Dur).ToString("yyyy-MM-dd");
                    }
                }
                if (Tproject.LoanTime != null)
                {
            <tr>
                <td>@EndTime</td>
                <td>@Math.Round(BenJin, 2)</td>
                <td>@Math.Round(YuQi, 2)</td>
                <td>@Math.Round(-FuWu, 2)</td>
                <td>@Math.Round(HuiShou, 2)</td>
                <td>@plan.statusName</td>
            </tr>
                }

            }
        }
        @if (Tproject.LoanTime != null)
        {
            <tr class="total">
                <td>总计</td>
                <td>@Math.Round(investment.TenderAmt, 2)</td>
                <td>@sumYuQi</td>
                <td>@sumFuWu</td>
                <td>@Math.Round((sumHuiShou + investment.TenderAmt), 2)</td>
                <td></td>
            </tr>
        }

    </table>
    <div class="button">
        <a id="btnDownload" class="btn">下载合同</a>
        <a id="btnCancle" onclick="window.parent.location.reload()" class="btn">返回</a>
    </div>
</div>
<iframe id="down_file" style="display: none;"></iframe>


